const cars = {
	// namespace: true,
	state() {
		return {
			CarsList: []
		}
	},
	mutations: {
		setCarsList(state, params) {
			// console.log(state, params, '参数')
			let {
				item,
				num
			} = params;
			let caritem = {
				goodsid: item.id || item.goodsid,
				numvalue: num,
				name: item.name,
				thumb: item.thumb,
				price: item.price,
				before_price: item.before_price
			}
			let idx = state.CarsList.findIndex(car => {
				return car.goodsid == caritem.goodsid
			})
			if (idx < 0) {
				state.CarsList.unshift(caritem)
			} else {
				state.CarsList[idx].numvalue = caritem.numvalue;
				if (state.CarsList[idx].numvalue <= 0) state.CarsList.splice(idx, 1)
				console.log(state.CarsList);
			}


		}


	}
}

export default cars